package me.landery.modules.sinco.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import me.landery.base.BaseEntity;
import me.landery.modules.system.domain.User;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @Author cc.w
 * @Date 2022/6/7 22:14
 * @Version 1.0
 */
@Entity
@Getter
@Setter
@Table(name="sinco_vip")
public class Vip extends BaseEntity implements Serializable {
    @Id
    @Column(name = "vid")
    @NotNull(groups = BaseEntity.Update.class)
    @ApiModelProperty(value = "VIP记录ID", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id; //订单id

    @OneToOne
    @JoinColumn(name = "uid")
    @ApiModelProperty(value = "VIP用户")
    private User user;

    @ManyToOne
    @JoinColumn(name = "pid")
    @ApiModelProperty(value = "VIP用户的当前套餐类型")
    private Mode mode;

    // todo
    // vip用户这里，如果有人一开始买了一周的套餐，然后又买了一个月的套餐，此时用户当前套餐是最后一次购买的套餐
    // 剩余调用数量自动延长到累加的到期时间？？？还是按照各自的购买时间？？？
    // 目前先按照所有调用数量自动延长到累加的到期时间来算

    @ApiModelProperty(value = "用户的余额")
    private Double balance;

    @ApiModelProperty(value = "VIP用户剩余可调用次数")
    private Long quota;

    @ApiModelProperty(value = "VIP用户用完之后赠送的次数之后，继续调用的价格")
    private Double price;

    @ApiModelProperty(value = "到期时间")
    private Date expiration;

    @ApiModelProperty(value = "佣金")
    private Double profit;


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Vip vip = (Vip) o;
        return Objects.equals(id, vip.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
